package com.chixing.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectRabbitConfig implements BeanPostProcessor {
    // 添加通知交换机和队列配置
    @Bean
    public DirectExchange notificationExchange() {
        return new DirectExchange("notification_exchange");
    }

    @Bean
    public Queue ticketPurchasedQueue() {
        return new Queue("ticket_purchased_queue");
    }

    @Bean
    public Queue ticketRefundedQueue() {
        return new Queue("ticket_refunded_queue");
    }

    @Bean
    public Binding ticketPurchasedBinding() {
        return BindingBuilder.bind(ticketPurchasedQueue()).to(notificationExchange()).with("ticket.purchased");
    }

    @Bean
    public Binding ticketRefundedBinding() {
        return BindingBuilder.bind(ticketRefundedQueue()).to(notificationExchange()).with("ticket.refunded");
    }

}
